import puppeteer from '../../../lib/puppeteer/puppeteer.js'
import { PluginResources } from '../components/index.js'

class Render {
    constructor() {
    }

    async userInfo(baseData, roleData) {
        roleData.roleList.sort((a, b) => {
            return b.starLevel - a.starLevel
        })
        const base64 = await puppeteer.screenshot('mingchao-plugin', {
            saveId: 'userInfo',
            imgType: 'png',
            tplFile: `${PluginResources}/html/user/userInfo.html`,
            PluginResources,
            baseData,
            roleData
        })

        return base64
    }

    async dailyData(gameData) {
        const base64 = await puppeteer.screenshot('mingchao-plugin', {
            saveId: 'dailyData',
            imgType: 'png',
            tplFile: `${PluginResources}/html/user/dailyData.html`,
            PluginResources,
            gameData
        })

        return base64
    }

    async calaBashData(baseData, calabashData) {
        if (!calabashData.phantomList) {
            calabashData.phantomList = []
        }
        calabashData.phantomList.sort((a, b) => {
            return b.star - a.star
        })
        const base64 = await puppeteer.screenshot('mingchao-plugin', {
            saveId: 'calaBash',
            imgType: 'png',
            tplFile: `${PluginResources}/html/user/calaBash.html`,
            PluginResources,
            baseData,
            calabashData,
        })

        return base64
    }

    async signInData(signInData) {
        const base64 = await puppeteer.screenshot('mingchao-plugin', {
            saveId: 'signIn',
            imgType: 'png',
            tplFile: `${PluginResources}/html/user/signIn.html`,
            PluginResources,
            signInData
        })

        return base64
    }
}

export default new Render()